//240.搜索二维矩阵II
//https://leetcode.cn/problems/search-a-2d-matrix-ii/?envType=study-plan-v2&envId=top-100-liked
class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        int n = matrix[0].size();
        for(vector<int>& v:matrix)
        {
            //对每一行的数组进行二分查找
            int l = 0,r = n-1;
            while(l < r)
            {
                int mid = (l+r)/2;
                if(target <= v[mid]) r = mid;
                else l = mid+1;
            }
            if(v[l] == target) return true;
        }
        return false;
    }
};